import { getAllRoleList, getOrgList, getUserMenus } from '@/api/sys/system';
import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import _ from '@/utils/math';
import { useI18n } from '@/hooks/web/useI18n';
const { t } = useI18n();
export const columns: BasicColumn[] = [
  {
    title: t('用户名'),
    dataIndex: 'username',
    width: 120,
  },
  {
    title: t('姓名'),
    dataIndex: 'name',
    width: 120,
  },
  {
    title: t('角色'),
    dataIndex: 'roleName',
    width: 120,
  },
  {
    title: '组织',
    dataIndex: 'orgName',
    width: 120,
  },
  {
    title: t('状态'),
    dataIndex: 'statusStr',
    width: 120,
    fixed: 'right',
  },
  {
    title: t('创建时间'),
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: t('更新时间'),
    dataIndex: 'updateTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    componentProps: {
      placeholder: '请输入用户名',
    },
  },
  {
    field: 'name',
    label: '姓名',
    component: 'Input',
    componentProps: {
      placeholder: '请输入姓名',
    },
  },
];
export const accountFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'username',
    label: t('用户名'),
    component: 'Input',
    required: true,
  },
  {
    label: t('姓名'),
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: t('角色'),
    field: 'roleId',
    component: 'ApiSelect',
    componentProps: {
      api: getAllRoleList,
      labelField: 'name',
      valueField: 'id',
      mode: 'multiple',
    },
    required: true,
  },
  {
    label: '组织',
    field: 'orgId',
    component: 'ApiTreeSelect',
    componentProps: {
      api: getOrgList,
      multiple: true,
      treeDefaultExpandAll: true,
      fieldNames: {
        label: 'title',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
      showSearch: true,
      treeNodeFilterProp: 'title',
    },
    required: true,
  },
  {
    label: '自定义欢迎页',
    field: 'welcomeRoute',
    component: 'ApiTreeSelect',
    componentProps: {
      api: getUserMenus,
      labelField: 'name',
      replaceFields: {
        key: 'id',
        value: 'id',
      },
    },
  },
];
